package com.dykj.fireFighting.web.app;

import com.dykj.fireFighting.api.base.maintenance.dto.MaintenanceStatisticsDto;
import com.dykj.fireFighting.api.base.maintenance.dto.UrgentMaintenanceDto;
import com.dykj.fireFighting.api.base.maintenance.service.IUrgentMaintenanceService;
import com.dykj.fireFighting.api.base.maintenance.vo.MaintenanceEvaluationVo;
import com.dykj.fireFighting.api.base.maintenance.vo.MaintenanceStatisticsVo;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;


/**
 * 紧急维保记录接口
 *
 * @Author JacksonTu
 * @Date 2021-07-28 08:38:40
 */
@Slf4j
@Api(value = "app维保记录接口", tags = {"app维保记录接口"})
@RestController
@RequestMapping("/app/maintenance")
public class AppMaintenanceStatisticsController {

    @DubboReference
    private IUrgentMaintenanceService urgentMaintenanceService;

    /**
     * 维保数据统计
     *
     * @return
     */
    @AutoLog(value = "维保数据统计")
    @ApiOperation(value = "维保数据统计", notes = "维保数据统计")
    @GetMapping("/statistic")
    public CommonResult<List<MaintenanceStatisticsVo>> getMaintenanceStatistics(MaintenanceStatisticsDto maintenanceStatisticsDto) {
        String wbId = ShiroUtil.getUser().getEnterpriseId().toString();
        maintenanceStatisticsDto.setWbId(wbId);
        List<MaintenanceStatisticsVo> maintenanceStatisticsVoList = urgentMaintenanceService.getMaintenanceStatistics(maintenanceStatisticsDto);
        return CommonResult.success(maintenanceStatisticsVoList);
    }

    /**
     * 今日维保数据统计
     *
     * @return
     */
    @AutoLog(value = "今日维保数据统计")
    @ApiOperation(value = "今日维保数据统计", notes = "今日维保数据统计")
    @GetMapping("/todayStatistic")
    public CommonResult<List<Integer>> getMaintenanceTodayStatistic() {
        String wbId = ShiroUtil.getUser().getEnterpriseId().toString();
        List<Integer> numList = urgentMaintenanceService.getMaintenanceTodayStatistic(wbId);
        return CommonResult.success(numList);
    }

    /**
     * 待处理/紧急维保  统计
     *
     * @return
     */
    @AutoLog(value = "待处理/紧急维保  统计")
    @ApiOperation(value = "待处理/紧急维保  统计", notes = "待处理/紧急维保  统计")
    @GetMapping("/getNotFinishedMaintenanceStatistics")
    public CommonResult<MaintenanceStatisticsVo> getNotFinishedMaintenanceStatistics() {
        String wbId = ShiroUtil.getUser().getEnterpriseId().toString();
        MaintenanceStatisticsVo maintenanceStatisticsVo = urgentMaintenanceService.getNotFinishedMaintenanceStatistics(wbId);
        return CommonResult.success(maintenanceStatisticsVo);
    }

    /**
     * 维保服务机构的当月评价得分
     *
     * @param urgentMaintenanceDto
     * @return
     */
    @AutoLog(value = "维保机构当月评价得分")
    @ApiOperation(value = "维保机构当月评价得分", notes = "维保机构当月评价得分")
    @GetMapping("/queryMaintenanceEvaluationList")
    public CommonResult<List<MaintenanceEvaluationVo>> queryMaintenanceEvaluationList(UrgentMaintenanceDto urgentMaintenanceDto) {
        String unitId = ShiroUtil.getUser().getEnterpriseId().toString();
        urgentMaintenanceDto.setMaintenanceDept(unitId);
        List<MaintenanceEvaluationVo> maintenanceEvaluationVoList = urgentMaintenanceService.queryMaintenanceEvaluationList(urgentMaintenanceDto);
        return CommonResult.success(maintenanceEvaluationVoList);
    }

    /**
     * 维保机构当月所有被服务的社会单位评价得分的平均值
     *
     * @param urgentMaintenanceDto
     * @return
     */
    @AutoLog(value = "维保机构当月评价得分的平均值")
    @ApiOperation(value = "维保机构当月评价得分的平均值", notes = "维保机构当月评价得分的平均值")
    @GetMapping("/queryMaintenanceEvaluationAvg")
    public CommonResult<BigDecimal> queryMaintenanceEvaluationAvg(UrgentMaintenanceDto urgentMaintenanceDto) {
        String unitId = ShiroUtil.getUser().getEnterpriseId().toString();
        urgentMaintenanceDto.setMaintenanceDept(unitId);
        BigDecimal monthAvgScore = urgentMaintenanceService.queryMaintenanceEvaluationAvg(urgentMaintenanceDto);
        return CommonResult.success(monthAvgScore);
    }

}
